/** Copyright 2014, Ross Mahony. Some rights reserved. See COPYING. */
package controllers

import play.api._
import play.api.mvc._
import play.api.db.slick._

import views._
import models._

import play.api._
import play.api.mvc._
import play.api.data._
import play.api.data.format.Formats._ 
import play.api.data.Forms._
import play.api.db.slick._
import play.api.db.slick.{ Session => SlickSession }

/** [[play.api.mvc.Controller]] class for the Reset view. */
object Reset extends Controller {

  /** Action to view the reste page. */
  def index = Action { implicit request =>
    Ok(html.reset.index())
  }  

  /** Reset the database back to its original state. */
  def reset = DBAction { implicit rs =>
    Logger.debug("Reseting database")
    
    TipDAO.dropTipTables

    EnergyUsageDAO.deleteAll
    PropertyDAO.deleteAll
    TipDAO.deleteAll
    RoadmapDAO.deleteAll
    CustomerDAO.deleteAll

    utils.InitialData.insert

    Logger.debug("Reseting database completed")

    Redirect(routes.Reset.index()).flashing("success" -> "Database has been reset")
    
  }

}